package com.zk5_education.config.ExceptionHandle;

import com.zk5_education.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandle {

//  全局异常处理
    @ExceptionHandler(Exception.class)
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message("全局异常");
    }

//   自定义异常
    @ExceptionHandler(MyException.class)
    public R error(MyException e){
        log.error(e.getMessage());
        return R.error().code(e.getCode()).message(e.getMeg());
    }
}
